package model.database;

import java.io.OutputStream;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLXML;
import java.sql.Types;

import javax.annotation.PostConstruct;


public class CallStatement extends BaseCallStatement {
	
	
	
	/**
	 * CallStatement prepare for get xml data and put xml data
	 * @param storeProcedureName store procedure name
	 * @param xmlSerialisedObject 
	 * @throws Exception
	 */
	public CallStatement(String storeProcedureName, OutputStream xmlSerialisedObject, int returnedType, int inOutType) throws Exception {
		
		callableStatement = connection.prepareCall(leftPartSql+storeProcedureName+rightPartSql); //Get CallableStatement object
		callableStatement.registerOutParameter(returnedDataNumber, returnedType); //type returned parameter
		SQLXML sqlxml = connection.createSQLXML();			//create sqlxml object
		sqlxml.setString(xmlSerialisedObject.toString());	// and fill it data
//		OutputStream outputStream = sqlxml.setBinaryStream();
//		outputStream = xmlSerialisedObject;
		callableStatement.setSQLXML(xmlDataNumber, sqlxml);	//type of inout parameter
		callableStatement.registerOutParameter(xmlDataNumber, inOutType); // typ of inout parameter
	}
	
	public SQLXML returnOutDataXml() throws Exception {
		return callableStatement.getSQLXML(returnedDataNumber);
	}
	
	public SQLXML returnInOutDataXml() throws Exception {
		return callableStatement.getSQLXML(xmlDataNumber);
	}
	
	public ResultSet returnResultSet() throws Exception {
		return (ResultSet) callableStatement.getObject(returnedDataNumber);
	}

}
